package first.niuke.simple;

/**
 * @ClassName NC48
 * @description:
 * @author: 荣燊
 * @create: 2021-06-15 15:00
 **/
public class NC48 {
    // 在旋转过的有序数组中寻找目标值
    public static void main(String[] args) {
        int[] nums = {8,10,12,14,0,2,4};
        int target = 2;
        System.out.println(search(nums, target));
    }

    public static int search (int[] nums, int target) {
        // write code here
        int left=0;
        int right=nums.length-1;
        int mid=(left+right)>>1;
        while(left<right){
            if(nums[mid]==target){
                return mid;
            }
            if(nums[mid]<target&&target<=nums[right]){
                left=mid+1;
            }else{
                right=mid;
            }
            mid=(left+right)>>1;
        }
        return nums[mid]==target?mid:-1;
    }
}
